package com.mmall.controller.protal;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.mmall.common.ServerResponse;
import com.mmall.service.IProductService;
import com.mmall.vo.ProductDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Jillian on 2018/2/23.
 * 门户的产品相关接口
 */
@Controller
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse<ProductDetailVo> detail(Integer productId) {
        return iProductService.getProductDetail(productId);
    }

    /**
     *
     * 用户端的产品搜索接口
     * @param keyword 非必传
     * @param categoryId 非必传
     * @param pageNum
     * @param pageSize
     * @param orderBy 排序
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse<PageInfo> list(@RequestParam(value = "keyword",required = false)String keyword,
                                        @RequestParam(value = "categoryId",required = false)Integer categoryId,
                                        @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                        @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                                        @RequestParam(value = "orderBy",defaultValue = "")String orderBy
                                        ){
        return iProductService.getProductByKeyWordCategory(keyword,categoryId,pageNum,pageSize,orderBy);
    }
}
